#-*- coding:utf-8 -*-

from py2neo import Graph, Node, Relationship

neo_graph = Graph('http://localhost:7474', username='neo4j', password='996427')


def select_node_one(label=None,property_key=None,property_value=None):
    '''
    :param label: 标签名
    :param property_key: 属性名
    :param property_value: 属性值
    :return: 单个节点对象 limit 1
    '''
    node = neo_graph.find_one(
        label = label,
        property_key = property_key,
        property_value = property_value
    )
    return node


def select_node_more(label=None,property_key=None,property_value=None):
    '''
    :param label: 标签名
    :param property_key: 属性名
    :param property_value: 属性值
    :return: 节点列表
    '''
    nodes = neo_graph.find(
        label = label,
        property_key = property_key,
        property_value = property_value
    )
    return nodes

def select_relationship_one(start_node=None,end_node=None,rel_type=None,bidirectional=False):
    '''
    :param start_node: 起始节点
    :param end_node: 结束节点
    :param rel_type: 关系类型
    :param bidirectional: 默认为单向
    :return: 单个关系对象 limit 1
    '''
    relationship = neo_graph.match_one(
        start_node = start_node,
        end_node = end_node,
        rel_type = rel_type,
        bidirectional = bidirectional
    )
    return relationship

def select_relationship_more(start_node=None,end_node=None,rel_type=None,bidirectional=False):
    '''
    :param start_node: 起始节点
    :param end_node:  结束节点
    :param rel_type: 关系类型
    :param bidirectional: 默认为单向
    :return: 所有关系列表
    '''
    relationships = neo_graph.match(
        start_node = start_node,
        end_node = end_node,
        rel_type = rel_type,
        bidirectional = bidirectional
    )
    return relationships



